package com.springStudy.boot.redis.firstDemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisUtils {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void setString(String key, String value, Long timeOut) {
        stringRedisTemplate.opsForValue().set(key,value);
        if(timeOut!=null ) {
            stringRedisTemplate.expire(key, timeOut, TimeUnit.SECONDS);
        }

    }
}
